/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace DaveSexton.DocProject.DocSites
{
	public sealed class IndexMatchSorter : Comparer<IndexMatch>
	{
		#region Public Properties
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
		public static new readonly IndexMatchSorter Default = new IndexMatchSorter();

		public bool Ascending
		{
			get
			{
				return ascending;
			}
		}
		#endregion

		#region Private / Protected
		private readonly bool ascending;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="IndexMatchSorter" /> class.
		/// </summary>
		public IndexMatchSorter()
		{
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="IndexMatchSorter" /> class.
		/// </summary>
		public IndexMatchSorter(bool ascending)
		{
			this.ascending = ascending;
		}
		#endregion

		#region Methods
		public override int Compare(IndexMatch x, IndexMatch y)
		{
			if (x == y)
				return 0;
			else
			{
				IndexMatch first = (ascending) ? x : y;
				IndexMatch second = (ascending) ? y : x;

				return first.Rank.CompareTo(second.Rank);
			}
		}
		#endregion
	}
}
